package stripesbook.view;

import static net.sourceforge.stripes.util.HtmlUtil.encode;

import org.stripesbook.rayures.view.stripes.SCheckBox;
import org.stripesbook.rayures.view.stripes.SErrors;
import org.stripesbook.rayures.view.stripes.SForm;
import org.stripesbook.rayures.view.stripes.SLink;
import org.stripesbook.rayures.view.stripes.SParam;

import stripesbook.action.user.folders.MessageDetailsActionBean;
import stripesbook.model.Folder;
import stripesbook.model.Message;

public class MessageListForm extends SForm {
  private Folder folder;

  public SForm folder(Folder folder) {
    this.folder = folder;
    return getThis();
  }

  public Folder getFolder() {
    return folder;
  }

  public SCheckBox getCheckBoxFor(Integer messageId) {
    return tag(SCheckBox.class).name("selectedMessages").value(messageId);
  }

  public SErrors getErrorsForField() {
    return tag(SErrors.class).field("selectedMessages");
  }

  public SLink getLinkFor(Message message) {
    return tag(SLink.class).beanclass(MessageDetailsActionBean.class).label(encode(message.getSubject()))
      .add(tag(SParam.class).name("message").value(message.getId()));
  }
}
